import React, { Component } from "react";
import { Table, Button, Pagination } from "antd";
import { SearchOutlined, RollbackOutlined } from "@ant-design/icons";
import type { PaginationProps } from "antd";
import "./table.less";
import { httpPost } from "../../api";

export default class table extends Component<any, any> {
  state = {
    dataSource: [],
  };

  onShowSizeChange: PaginationProps["onShowSizeChange"] = (
    current,
    pageSize
  ) => {
    console.log(current, pageSize);
  };

  search = () => {
    httpPost(this.props.queryUrl, this.props.searchParams).then((res: any) => {
      console.log("res:", res);
      this.setState({
        dataSource: res.rows,
      });
    });
  };

  componentDidMount(): void {
    this.search();
  }
  render() {
    // console.log("获取到父组件的搜索条件组件：", this.props.searchContent);
    // console.log("获取到父组件的搜索条件值：", this.props.searchParams);

    return (
      <div>
        <div className="search">
          <div className="search-params">{this.props.searchContent}</div>
          <div className="search-btns">
            <Button
              className="search-btns-search"
              type="primary"
              icon={<SearchOutlined />}
              onClick={() => this.search()}
            >
              搜索
            </Button>
            <Button
              className="search-btns-reset"
              onClick={() => this.props.searchReset()}
            >
              重置
            </Button>
          </div>
        </div>
        <div className="table">
          <Table
            dataSource={this.state.dataSource}
            columns={this.props.tableColumns}
          />
        </div>
      </div>
    );
  }
}
